﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CommonHelper.Model;
using CommonHelper.Server;
using WeiXinGeneralApi.Models;

namespace WeiXinGeneralApi.Controllers
{
    public class TemplateMessageController : Controller
    {
        //
        // GET: /TemplateMessage/
        [HttpGet]
        public ActionResult Send()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Send(TemplateMessageDto dto)
        {
            var message = string.Empty;
            try
            {
                var tempId=TemplateMessage.NoticeTemplateId;
                var data=TemplateMessage.NoticeTemplate(dto.First,dto.Keyword1,dto.Keyword2,dto.Keyword3,dto.Keyword4);
                var isSuccess=SendTemplateMessageService.SendMessage(tempId,dto.OpenId,dto.Url,data);
                message =isSuccess?"发送成功!":"该OpenId未关注对应公众号";
            }
            catch (Exception e)
            {
                message = e.Message;
            }
            return Json(message);
        }
    }
}
